package com.systop.demoswagger.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {

//    http://localhost:8080/swagger-ui.html访问
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) //扫描有注解的api
//                .apis(RequestHandlerSelectors.basePackage("com.systop.demoswagger.controller")) //扫描的包
                .paths(PathSelectors.any())
                .build();
    }

//    配置文档信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot整合Swagger")  //标题
                .description("Swagger文档")   //描述
//                联系人信息 Contact("联系人名字", "http://xxx.xxx.com/联系人访问链接", "联系人邮箱");
                .contact(new Contact("璒璒","https://blog.csdn.net/kriswu_deng?type=blog","1486953997@qq.com"))
                .version("1.0")  //版本号
                .build();
    }

}
